package com.supermap.guangzhou.weifang.utils;

import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.rest.CacheMode;
import com.yanzhenjie.nohttp.rest.OnResponseListener;
import com.yanzhenjie.nohttp.rest.RequestQueue;
import com.yanzhenjie.nohttp.rest.Response;
import com.yanzhenjie.nohttp.rest.StringRequest;

/**
 * Created by XueQing Wang on 2018/5/28.
 */

public abstract class NetUtils<T> {
    RequestQueue requestQueue = NoHttp.newRequestQueue();

    public NetUtils(StringRequest request) {
        doGet(request);
    }

    public  void doGet(StringRequest request){
        request.setCacheMode(CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE);


        requestQueue.add(0, request, new OnResponseListener<String>() {
            @Override
            public void onStart(int what) {

            }

            @Override
            public void onSucceed(int what, Response<String> response) {
                onSuccess(response);
            }

            @Override
            public void onFailed(int what, Response<String> response) {
                onFail(response);
            }

            @Override
            public void onFinish(int what) {

            }
        });
    }

        public abstract T onSuccess(Response<String> response);
        public abstract T onFail(Response<String> response);
}
